<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Row Editing in DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/demo.css">
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <script type="text/javascript" src="./jquery-easyui/js/jquery.min.js"></script>
    <script type="text/javascript" src="./jquery-easyui/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./js/common/common.js"></script>
    <script type="text/javascript" src="./js/common/url.js"></script>
    <script type="text/javascript" src="./js/common/loader.js"></script>
    <script type="text/javascript ">
    var url;
    /*全校学生信息库的查询*/
    function doStuSearch() {
        var val = $('#stu_cc').combobox('getValue');
        // var deptIds = val.join(',')
        $('#addZGtable').datagrid('load', {
            stuId: $('#stu_stuId').val(), //用户名
            name: $('#stu_name').val(), //用户名
            bankName: $('#stu_bankName').val(),
            deptId:val //deptName
        });
    }

    function doSearch() {
        var val = $('#cc').combobox('getValues');
        var deptIds = val.join(',')

        $('#tt').datagrid('load', {
            stuId: $('#stuId').val(), //用户名
            name: $('#name').val(), //用户名
            bankName: $('#bankName').val(),
            deptId: deptIds //deptName
        });
    }

    function editUser() {
        var row = $('#tt').datagrid('getSelected');
        console.log(row);
        if (row) {
            $('#dlg').dialog('open').dialog('center').dialog('setTitle', '编辑助管信息');
            $('#fm').form('clear');
            $("#add_stuId").textbox('setValue', row.stuId);
            $("#add_stuId").textbox('readonly', true);

            $("#add_name").textbox('setValue', row.name);
            $("#add_name").textbox('readonly', true);
            $("#add_deptId").textbox('setValue', row.deptId);
            $("#add_bankName").textbox('setValue', row.bankName);
            $("#add_bankNo").textbox('setValue', row.bankNo);
            $("#add_telephone").textbox('setValue', row.telephone);
            url = url_editZG;

        } else {
            alert('请先选择一名助管')
        }
    }
    // 添加助管对话框
    function newZG() {
        $('#addZGdlg').dialog('open').dialog('center').dialog('setTitle', '添加助管信息');
        // $('#fm').form('clear');
    }

    function saveZG() {
        var row = $('#addZGtable').datagrid('getSelections');
        var ids = [];
        $.each(row, function(i, val) {
            // console.log();
            ids.push(val.stuId);
        })
        var stuIds = ids.join(',')
        console.log(ids);
        if (row) {
            var data = {
                "stuIds": stuIds
            }
            $.ajax({
                type: "POST",
                url: zhuguan_url.addZhuguan,
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data),
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(result) {
                    if (status == 0) {
                        $.messager.show({ // show error message
                            title: 'Success',
                            msg: result.message
                        });
                        $('#addZGdlg').dialog('close'); // close the dialog
                        $('#tt').datagrid('reload'); // reload the user data
                    } else {
                        $.messager.show({ // show error message
                            title: 'Error',
                            msg: result.message
                        });
                    }
                }
            })
        }
    }

    function addZGEx() {
        $('#addZG').dialog('open').dialog('center').dialog('setTitle', '添加助管信息');
        $('#fmEx').form('clear');
    }

    function uploadExcel() {
        var formData = new FormData();
        formData.append('uploadExcel', $('#file')[0].files[0]);
        $.ajax({
            url: url_uploadFile,
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function(res) {
            alert('提交数据成功')
            $('#addZG').dialog('close');
            $('#tt').datagrid('reload');
        }).fail(function(res) {
            alert('提交数据失败')
        });
    }

    function saveUser() {
        var data = $("#fm").serializeObject();
        if ($("#fm").form('validate')) {
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(result) {
                    if (result.status == 1) {
                        $('#dlg').dialog('close'); // close the dialog
                        $('#tt').datagrid('reload'); // reload the user data
                    } else {
                        $.messager.show({ // show error message
                            title: 'Error',
                            msg: result.message
                        });
                    }
                }
            })
        };
    }

    function destroyUser() {
        var row = $('#tt').datagrid('getSelected');
        console.log(row);
        if (row) {
            $.messager.confirm('确认', '你确定要删除该助管吗？', function(r) {
                if (r) {
                    var query = {
                        stuId: row.stuId
                    }
                    $.ajax({
                        type: "POST",
                        url: url_delZG,
                        data: JSON.stringify(query),
                        contentType: "application/json; charset=utf-8",
                        dataType: 'json',
                        xhrFields: {
                            withCredentials: true
                        },
                        crossDomain: true,
                        success: function(result) {
                            if (result.status == 1) {
                                $('#tt').datagrid('reload'); // reload the user data
                            } else {
                                $.messager.show({ // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        }
                    })
                }
            });
        }
    }
    $(function() {
        $('#tt').datagrid({
            title: '添加助管，删除助管，编辑助管',
            iconCls: 'icon-edit',
            width: "100%",
            height: "auto",
            fit: true,  
            
            singleSelect: true,
            idField: 'id',
            url: url_queryZhuguan,
            pagination: true,
            pageSize: 10,
            pageList: [5, 10, 15, 20],
            method: 'post',
            columns: [
                [{
                        field: 'stuId',
                        title: '学号',
                        align: 'center',
                        width: "20%"
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                        width: "12%"
                    },
                    // {
                    //     field: 'lqzyId',
                    //     title: '所在学院编号',
                    //     align: 'center',
                    //     width: "auto"
                    // }, {
                    //     field: 'lqzyName',
                    //     title: '所在学院名称',
                    //     width: "25%",
                    //     align: "auto"
                    // }, 
                    {
                        field: 'deptId',
                        title: '设岗学院/部门编号',
                        align: 'center',
                        width: "12%"
                    }, {
                        field: 'deptName',
                        title: '所在学院/部门名称',
                        width: "15%",
                        align: 'center',
                    },
                    // {
                    //     field: 'dsName',
                    //     title: '导师姓名',
                    //     width: "auto",
                    //     align: 'center',
                    // }, 
                    {
                        field: 'bankName',
                        title: '银行',
                        width: "12%",
                        align: 'center',
                    }, {
                        field: 'bankNo',
                        title: '银行卡号',
                        width: "17%",
                        align: 'center',
                    }, {
                        field: 'telephone',
                        title: '电话号码',
                        width: "12%",
                        align: 'center',
                    }
                ]
            ],
            toolbar: '#toolbar',
            onDblClickRow: function() {
                editUser()
            }
        });
        $('#addZGtable').datagrid({
            title: '添加助管，删除助管，编辑助管',
            iconCls: 'icon-edit',
            width: "100%",
            height: "auto",
            singleSelect: false,
            idField: 'id',
            url: 'http://115.29.136.190:8080/help/base/stu/searchStudent1.do',
            pagination: true,
            pageSize: 10,
            pageList: [5, 10, 15, 20],
            method: 'post',
            columns: [
                [{
                    field: 'stuId',
                    title: '学号',
                    align: 'center',
                    width: "17%"
                }, {
                    field: 'stuName',
                    title: '姓名',
                    align: 'center',
                    width: "10%"
                }, {
                    field: 'lqzyId',
                    title: '录取学院编号',
                    align: 'center',
                    width: "15%"
                }, {
                    field: 'lqzyName',
                    title: '录取学院名称',
                    width: "18%",
                    align: "auto"
                }, {
                    field: 'deptId',
                    title: '所在学院/部门编号',
                    align: 'center',
                    width: "12%"
                }, {
                    field: 'deptName',
                    title: '所在学院/部门名称',
                    width: "18%",
                    align: 'center',
                }, {
                    field: 'dsName',
                    title: '导师姓名',
                    width: "10%",
                    align: 'center',
                }]
            ],
            toolbar: '#addZGtt'
        });
        $('#cc').combobox({
            url: url_queryDept,
            valueField: 'deptId',
            textField: 'deptName',
            method: 'post',
            multiple: true,
            loader: cloader,
            panelHeight: 200,
        });
        $('#stu_cc').combobox({
            url: url_queryDept,
            valueField: 'deptId',
            textField: 'deptName',
            method: 'post',
            multiple: false,
            loader: cloader,
            panelHeight: 200,
        })
    });
    </script>
</head>

<body>
    <!-- <h2>助管信息管理</h2> -->
    <!-- <p></p> -->
    <div id="toolbar">
        <div id="ts" style="padding:3px">
            <span>学号:</span>
            <input id="stuId" style="line-height:26px;border:1px solid #ccc">
            <span>姓名:</span>
            <input id="name" style="line-height:26px;border:1px solid #ccc">
            <span>银行:</span>
            <input id="bankName" style="line-height:26px;border:1px solid #ccc">
            <span>部门名称:</span>
            <input id='cc' name='deptName' value="">
            <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="doSearch()">Query</a>
            <!-- <a href="#" class="easyui-linkbutton" plain="true" >Search</a> -->
        </div>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newZG()">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
        <div>
            <a href='http://115.29.136.190:8080/help/base/stu/downloadMB.do' class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">点击下载上传文件的模板</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addZGEx()">添加助管信息(通过文件)</a>
        </div>
    </div>
    <!-- 用户信息表格 -->
    <table id="tt"></table>
    <!-- 编辑助管对话框 -->
    <div id="dlg" class="easyui-dialog" style="width:500px" closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">助管信息</div>
            <div style="margin-bottom:10px">
                <input id="add_stuId" name="stuId" class="easyui-textbox" required="true" label="学号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="add_name" name="name" class="easyui-textbox" required="true" label="姓名" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="add_deptId" name="deptId" class="easyui-textbox" label="部门编号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="add_bankName" name="bankName" class="easyui-textbox" label="银行" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="add_bankNo" name="bankNo" class="easyui-textbox" label="银行卡号" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="add_telephone" name="telephone" class="easyui-textbox" label="电话号码" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <!-- 添加助管对话框（文件上传） -->
    <div id="addZG" class="easyui-dialog" style="width:500px" closed="true" buttons="#dlg-buttons">
        <form id="fmEx" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">添加助管信息</div>
            <div style="margin-bottom:10px">
                <input name="uploadExcel" id="file" class="easyui-textbox" type="file" required="true" label="请选择文件:" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="uploadExcel()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addZG').dialog('close')" style="width:90px">Cancel</a>
    </div>
    <!-- 添加助管对话框（普通上传） -->
    <div id="addZGdlg" class="easyui-dialog" style="width:88%" closed="true" buttons="#dlg-buttons">
        <div id="addZGtt">
            <div id="addZGnor" style="padding:3px">
                <span>学号:</span>
                <input id="stu_stuId" style="line-height:26px;border:1px solid #ccc">
                <span>姓名:</span>
                <input id="stu_name" style="line-height:26px;border:1px solid #ccc">
                <span>银行:</span>
                <input id="stu_bankName" style="line-height:26px;border:1px solid #ccc">
                <span>部门编号:</span>
                <input id='stu_cc' class="easyui-combobox" name='stu_deptId' value="" style="line-height:26px;border:1px solid #ccc">
                <!-- <input id="stu_deptId" style="line-height:26px;border:1px solid #ccc"> -->
                <!--  <input id='cc' name='deptName' value=""> -->
                <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="doStuSearch()">Query</a>
            </div>
        </div>
        <!-- 助管信息表格 -->
        <table id="addZGtable"></table>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveZG()" style="width:90px">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addZGdlg').dialog('close')" style="width:90px">取消</a>
    </div>
</body>

</html>
